package logic

import (
	"context"
	"goods/models/mysql"

	"goods/goodsrpc/goodsrpc"
	"goods/goodsrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsShowLogic {
	return &GoodsShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsShowLogic) GoodsShow(in *goodsrpc.GoodsShowRequest) (*goodsrpc.GoodsShowResponse, error) {
	// todo: add your logic here and delete this line

	var goods mysql.Goods
	mysql.DB.Debug().Find(&goods)

	//var goodsShow []mysql.GoodData
	//offset := (in.Page - 1) * in.Size
	//mysql.DB.Debug().Model(&mysql.User{}).
	//	Select("users.*,  classes.NAME AS class_name ,goods.title AS good_name").
	//	Joins("LEFT JOIN goods ON goods.user_id = users.id").
	//	Joins("LEFT JOIN classes ON classes.id = goods.class_id").
	//	Offset(int(offset)).
	//	Limit(int(in.Size)).Find(&goodsShow)
	//
	//var goodsData []*goodsrpc.GoodList
	//for _, data := range goodsData {
	//	list := goodsrpc.GoodList{
	//		Title:   data.Title,
	//		ClassId: data.ClassId,
	//		Price:   data.Price,
	//		Info:    data.Info,
	//		UserId:  data.UserId,
	//	}
	//	goodsData = append(goodsData, &list)
	//}

	return &goodsrpc.GoodsShowResponse{
		Title:   goods.Title,
		ClassId: goods.ClassId,
		Price:   float32(goods.Price),
		Info:    goods.Info,
		UserId:  goods.UserId,
	}, nil
}
